package com.automannn.springPractice.applicationContext.bean.init;

import com.automannn.springPractice.applicationContext.bean.factory.UserFactory;
import com.automannn.springPractice.applicationContext.bean.factory.impl.DefaultUserFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

@Configuration
public class InitBeanCreateBean {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.register(InitBeanCreateBean.class);
        context.refresh();
        System.out.println("启动上下文");
        UserFactory userFactory = context.getBean(UserFactory.class);
        System.out.println(userFactory);
        System.out.println("上下文准备关闭");
        context.close();
        System.out.println("上下文关闭成功");
    }

    @Bean(initMethod = "customInit",destroyMethod = "customDestory")
    @Lazy
    public UserFactory getUserBeanFactory(){
        return new DefaultUserFactory();
    }

}
